package view;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JCheckBox;

import model.XMLWorker;

public class FilterCheckBox extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel = null;
	private JCheckBox jCheckBox = null;
	private JCheckBox jCheckBox1 = null;
	private EventTable eventTable = null;

	/**
	 * This is the default constructor
	 */
	public FilterCheckBox(EventTable e) {
		super();
		this.eventTable = e;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel = new JLabel();
		jLabel.setText("Filter:");
		jLabel.setPreferredSize(new Dimension(31, 20));
		FlowLayout flowLayout = new FlowLayout();
		flowLayout.setVgap(0);
		flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
		this.setLayout(flowLayout);
		this.setSize(500, 20);
		this.add(jLabel, null);
		this.add(getJCheckBox(), null);
		this.add(getJCheckBox1(), null);
	}

	/**
	 * This method initializes jCheckBox	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox() {
		if (jCheckBox == null) {
			jCheckBox = new JCheckBox();
			jCheckBox.setText("Geburtstage");
			jCheckBox.setPreferredSize(new Dimension(95, 20));
			jCheckBox.setSelected(true);
			jCheckBox.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					executeFilter();
				}
			});
		}
		return jCheckBox;
	}

	protected void executeFilter() {
		if(jCheckBox.isSelected()) {
			if(jCheckBox1.isSelected()) {
				eventTable.setFilter(XMLWorker.ALLE, 1);
			} else {
				eventTable.setFilter(XMLWorker.GEBURTSTAG, 1);
			}
		} else {
			if(jCheckBox1.isSelected()) {
				eventTable.setFilter(XMLWorker.TERMIN, 1);
			} else {
				eventTable.setFilter(XMLWorker.KEINE, 1);
			}			
		}
	}
	
	/**
	 * This method initializes jCheckBox1	
	 * 	
	 * @return javax.swing.JCheckBox	
	 */
	private JCheckBox getJCheckBox1() {
		if (jCheckBox1 == null) {
			jCheckBox1 = new JCheckBox();
			jCheckBox1.setText("Termine");
			jCheckBox1.setPreferredSize(new Dimension(72, 20));
			jCheckBox1.setSelected(true);
			jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					executeFilter();
				}
			});
		}
		return jCheckBox1;
	}

}
